/*
 ============================================================================
 Page	     : 188-189
 Name        : divisors.c
 Date	     : 20210403
 Author      : Hbue 18060333
 Copyright   : Your copyright notice
 Description : 使用嵌套if语句显示一个数的约数
 ============================================================================
 */

#include <stdio.h>
#include <stdbool.h>

int main(void)
{
	unsigned long num = 0;		// 待测试的数
	unsigned long div = 0;		// 可能的约数
	bool isPrime = true;		// 素数标记

	printf("Please enter an integer for analysis; ");
	printf("Enter q to quit.\n");
	while(scanf("%lu", &num) == 1)
	{
		for(div = 2, isPrime = true; (div * div) <= num; div++)
		{
			if(num % div == 0)
			{
				if((div * div) != num)
				{
					printf("%lu is divisible by %lu and %lu.\n", num, div, num / div);
				}
				else
				{
					printf("%lu is divisible by %lu.\n", num, div);
				}
				isPrime = false;		// 该数不是素数
			}
		}
		if(isPrime)
		{
			printf("%lu is prime.\n", num);
		}
		printf("Please enter another integer for analysis; ");
		printf("Enter q to quit.\n");
	}
	printf("Bye.\n");

	return 0;
}

